package at.jku.se.pr.quickshopper.activities;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;
import at.jku.se.pr.quickshopper.network.ServerConnection;

/**
 * class to declare constants
 */
public class Constants {
	
	/**
	 * time to wait for a network answer
	 */
	protected static final int NETWORK_TIMEOUT = 3000;
	
	/**
	 * value which is used to start the camera
	 */
	protected static final int ZBAR_SCANNER_REQUEST = 0;
	
	/**
	 * value, used to create a new JSON-Object
	 */
	protected static long scanResult;
	
	/**
	 * value referencing the current customer
	 */
	protected static long customer;
	
	/**
	 * method to create a new JSON-Object
	 * @param key
	 * @return responseString
	 */
	protected static String createJson(String key) {
		JSONObject o = new JSONObject();
		try {
			o.put(key, scanResult);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		String requestString = o.toString();
		Log.e("", "requestString: " + requestString);
		
		ServerConnection conn = new ServerConnection(requestString);
		conn.start();
		
		try {
			conn.join(NETWORK_TIMEOUT);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		String responseString = conn.getResult();
		Log.e("", "responseString: " + responseString);
		
		return responseString;
	}
	
}
